package ioc08;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.HashMap;
import java.util.Map;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/7 9:33
 * Version:1.0-SNAPSHOT
 */
public class Test {

    public static void main(String[] args) {
        // 预先实例化
        // ApplicationContext在解析容器的时候
        // 会将容器中所有的bean预先进行了实例化操作
        ApplicationContext ac = new ClassPathXmlApplicationContext("ioc08/spring.xml");
        System.out.println("----------------------");
        SomeBean someBean = (SomeBean) ac.getBean("someBean");

        // 延迟实例化
        // BeanFactory在解析容器的时候
        // 只是单纯做了解析,并没有对容器中的bean做额外处理
        // 只有当使用到容器中的bean的时候,才会对对应的bean进行实例化
        // 但是当一个bean被实例化之后,将会保存起来
        // 单例的
//        Resource resource = new ClassPathResource("ioc08/spring.xml");
//        BeanFactory bf = new XmlBeanFactory(resource);
//        System.out.println("-----------------------");
//        SomeBean someBean = (SomeBean) bf.getBean("someBean");
//        SomeBean someBean2 = (SomeBean) bf.getBean("someBean");
//        System.out.println(someBean);
//        System.out.println(someBean2);

    }

}
